/*   1:    */ package com.atomikos.timing;
/*   2:    */ 
/*   3:    */ import java.util.ArrayList;
/*   4:    */ import java.util.Iterator;
/*   5:    */ import java.util.List;
/*   6:    */ 
/*   7:    */ public final class PooledAlarmTimer
/*   8:    */   implements AlarmTimer
/*   9:    */ {
/*  10:    */   private final List listeners;
/*  11:    */   private final long timeout;
/*  12: 42 */   private final Object runMonitor = new Object();
/*  13: 43 */   private boolean runFlag = true;
/*  14:    */   
/*  15:    */   public PooledAlarmTimer(long timeout)
/*  16:    */   {
/*  17: 46 */     this.listeners = new ArrayList();
/*  18: 47 */     this.timeout = timeout;
/*  19:    */   }
/*  20:    */   
/*  21:    */   public void addAlarmTimerListener(AlarmTimerListener lstnr)
/*  22:    */   {
/*  23: 51 */     synchronized (this.listeners)
/*  24:    */     {
/*  25: 52 */       this.listeners.add(lstnr);
/*  26:    */     }
/*  27:    */   }
/*  28:    */   
/*  29:    */   public void removeAlarmTimerListener(AlarmTimerListener lstnr)
/*  30:    */   {
/*  31: 57 */     synchronized (this.listeners)
/*  32:    */     {
/*  33: 58 */       this.listeners.remove(lstnr);
/*  34:    */     }
/*  35:    */   }
/*  36:    */   
/*  37:    */   public long getTimeout()
/*  38:    */   {
/*  39: 63 */     return this.timeout;
/*  40:    */   }
/*  41:    */   
/*  42:    */   public boolean isActive()
/*  43:    */   {
/*  44: 67 */     synchronized (this.runMonitor)
/*  45:    */     {
/*  46: 68 */       return this.runFlag;
/*  47:    */     }
/*  48:    */   }
/*  49:    */   
/*  50:    */   public void stop()
/*  51:    */   {
/*  52: 73 */     synchronized (this.runMonitor)
/*  53:    */     {
/*  54: 74 */       this.runFlag = false;
/*  55: 75 */       this.runMonitor.notify();
/*  56:    */     }
/*  57:    */   }
/*  58:    */   
/*  59:    */   public void run()
/*  60:    */   {
/*  61: 85 */     while (isActive())
/*  62:    */     {
/*  63:    */       try
/*  64:    */       {
/*  65: 88 */         doWait(this.timeout);
/*  66:    */       }
/*  67:    */       catch (InterruptedException e) {}
/*  68: 98 */       if (isActive()) {
/*  69: 99 */         notifyListeners();
/*  70:    */       }
/*  71:    */     }
/*  72:    */   }
/*  73:    */   
/*  74:    */   private void notifyListeners()
/*  75:    */   {
/*  76:109 */     List tempList = new ArrayList(this.listeners);
/*  77:110 */     for (Iterator it = tempList.iterator(); it.hasNext();)
/*  78:    */     {
/*  79:111 */       AlarmTimerListener list = (AlarmTimerListener)it.next();
/*  80:112 */       list.alarm(this);
/*  81:    */     }
/*  82:    */   }
/*  83:    */   
/*  84:    */   private void doWait(long millis)
/*  85:    */     throws InterruptedException
/*  86:    */   {
/*  87:120 */     synchronized (this.runMonitor)
/*  88:    */     {
/*  89:122 */       this.runMonitor.wait(millis);
/*  90:    */     }
/*  91:    */   }
/*  92:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.timing.PooledAlarmTimer
 * JD-Core Version:    0.7.0.1
 */